const { defineConfig } = require('@vue/cli-service')
var jwt = require('jsonwebtoken');
const Mock = require("mockjs")
function addList() { // 每次的数据都不一样
  return Mock.mock({
    "list|6": [{
      "img": "@image(100x100,@color)",
      "tit": "@ctitle(3,5)",
      "price|100-1000":100,
       "checked":false,
       num:1,
       id:"@id"
    }]
  }).list
}

module.exports = defineConfig({
  transpileDependencies: true,
  devServer: {
    onBeforeSetupMiddleware({
      app
    }) {
      app.get("/api/shoplist", (req, res) => {
        res.send(addList())
      })
      app.get("/api/login",(req,res)=>{
        let {tel,yzm} = req.query
        if (tel == "13522402771" && yzm == "1234") {
         let token =  jwt.sign({
            exp: Math.floor(Date.now() / 1000) + (60 * 60),
            data: tel
          }, 'secret');
          res.send({
            code:1,
            msg:"登陆成功",
            token:token
          })
        } else {
          res.send({
            code:0,
            msg:"登陆失败"
          })
        }
       
      })
    }
  }
})
